package org.example.Mouse;

import java.awt.*;
import java.awt.Point;

/**
 *  java EE 鼠标的管理类
 *  setPosition 为 设置鼠标的位置
 *  getPosition 为 获取鼠标位置
 */
public class CrossPlatformMousePosition {

    public static void  setPosition(int targetX ,int targetY){
        try {
            // 创建 Robot 实例
            Robot robot = new Robot();

            // 移动鼠标到指定位置
            robot.mouseMove(targetX, targetY);

            // 验证新位置（可选）
            Point newPos = MouseInfo.getPointerInfo().getLocation();
            System.out.println("新鼠标位置: (" + newPos.x + ", " + newPos.y + ")");
        } catch (AWTException e) {
            System.err.println("无法控制鼠标: " + e.getMessage());
        }
    }
    public static MousePoint getPosition() {
            // 获取鼠标的屏幕坐标
            Point mousePoint = MouseInfo.getPointerInfo().getLocation();
            return  new MousePoint(mousePoint.x, mousePoint.y);
    }
}
